#include<bits/stdc++.h>
using namespace std;
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int T;
    cin>>T;
    int ss[T+10]={},s=0;
    while(T--){
        int n;
        scanf("%d",&n);
        int ans=0;
        int a[n+100]={};
        for(int i=1;i<=n;i++){
            scanf("%d",&a[i]);
        }
        sort(a+1,a+n+1);
        for(int i=2;i<=n;i++){
            if(a[i]==a[i-1]){
                ans+=a[i];
            }
        }
        ss[++s]=ans;
    }
    for(int i=1;i<=s;i++){
        cout<<ss[i]<<"\n";
    }
    return 0;
}
